finp$="p4572654wb_160x48.png"
if argc>=3 then:finp$=command$(3):end if
'- original qbasic version - 0112141818
'- sdlbasic version - 0405111338
'- halftone picture converter (bmp 4/8/24bit) 
xed=0:yed=0:open finp$ for input as #1:for i=1 to 16:n=readbyte(1):next:for i=1 to 2:n=readbyte(1):next
xed=readbyte(1)*256:xed=xed+readbyte(1):for i=1 to 2:n=readbyte(1):next:yed=readbyte(1)*256:yed=yed+readbyte(1)
close #1
setdisplay(xed,yed,32,1):paper(8^8-1):ink(0):pen(0):cls:
'- opens the image
loadimage(finp$,1):pasteicon(0,0,1)
dim clust[8,8] '-,o4b[2]
dim bndmp[16384]
'-- define cluster
' a$="00,12,03,15,08,04,11,07,02,14,01,13,10,06,09,05"
a$="00,06,08,14,02,12,04,10,08,14,00,06,04,10,02,12"
a$="00,06,09,15,02,12,05,11,08,14,01,07,04,10,03,13"
a$="00,10,01,11,04,14,05,15,08,02,09,03,12,06,13,07"
a$="00,04,08,12,10,14,02,06,01,05,09,13,11,15,03,07"
for y2=0 to 3:for x2=0 to 3:lc=(y2*4)+x2
  clust[x2,y2]=val(mid$(a$,(lc*3)+1,2)):next:next

qadr=0
for y1=0 to yed-1 step 2
  for x1=0 to xed-1 step 4
    qou=0
    for x2=0 to 3 step 2
     for y2=0 to 1
      for x3=0 to 1
        bq=(x3)+(y2+x2)*2
        y=y1+y2
        x=x1+x2+x3
        ind=point(x,y)
        b=ind mod 256:ind=int(ind/256)
        g=ind mod 256:ind=int(ind/256)
        r=ind mod 256
        k=int(((b*11)+(r*30)+(g*59))/100)
        patgf=(((clust[x mod 4,y mod 4]+1)*255)/16)
        kpat=0:if k>patgf then:kpat=1:end if
        ink(0):if kpat<>0 then
          ink(0xFFFFFF)
          qou=bitwiseor(qou,2^bq)
          end if
        dot(x,y)
        next:next:next
    bndmp[qadr]=qou
    qadr=qadr+1
    next:next
'- saves the image
fout$=finp$+".bmp"
grab (1,0,0,xed,yed):saveimage(fout$,1)
shell ("convert "+finp$+".bmp "+finp$+".png")
shell ("rm "+finp$+".bmp")


open finp$+".bin" for output as #2
for i=0 to (40*24)-1
  writebyte (2,bndmp[i])
  next
close #2






